"""
组织架构类
"""
from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from selenium.webdriver.support.select import Select


class OrganizationPage(BasePage):
    # 添加岗位定位器
    add_post_locator = (By.CSS_SELECTOR, "#add_role")
    # 岗位名
    post_name_locator = (By.CSS_SELECTOR, '#role_add > div:nth-child(1) > div > input')
    # 所属部门定位器
    select_locator = (By.NAME, "department_id")
    # 上级定位器
    up_locator = (By.NAME, "parent_id")
    # 岗位描述定位器
    post_description_locator = (By.CSS_SELECTOR, "#role_add > div:nth-child(4) > div > textarea")
    # 岗位保存按钮单位器
    save_btn_locator = (By.CSS_SELECTOR, "body > div:nth-child(10) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1) > span")
    # 添加部门
    add_department_locator = (By.ID, "add_department")
    # 部门名
    department_name_locator = (By.XPATH, "//*[@id='name']")
    # 上级部门
    drop_locator = (By.NAME, "parent_id")
    # 部门描述
    department_description_locator = (By.CSS_SELECTOR, "#department_add > div:nth-child(3) > div > textarea")
    # 部门保存按钮
    save_locator = (By.CSS_SELECTOR, "body > div:nth-child(9) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1)")
    # 点击修改按钮
    alter_locator = (By.CSS_SELECTOR, "#user_form > div:nth-child(2) > table > tbody > tr:nth-child(1) > td:nth-child(8) > a:nth-child(2) > i")
    # 点击查看按钮
    check_locator = (By.CSS_SELECTOR,"#user_form > div:nth-child(2) > table > tbody > tr:nth-child(1) > td:nth-child(8) > a:nth-child(1) > i")
    # 添加部门错误消息提示
    add_department_mistake_tips_locator=(By.CSS_SELECTOR,"body > div.container > div.alert.alert-success")
    # 添加部门成功信息提示
    add_department_success_tips_locator=(By.CSS_SELECTOR,"body > div.container > div.alert.alert-success")
    # 添加岗位成功信息提示
    add_post_success_tips_locator=(By.CSS_SELECTOR,"body > div.container > div.alert.alert-success")
    # 添加岗位失败信息提示
    add_post_mistake_tips_locator=(By.CSS_SELECTOR,"body > div.container > div.alert.alert-success")
    # 用户添加成功信息提示
    add_user_tips_locator=(By.CSS_SELECTOR,"body > div.container > div.alert.alert-success")
    # 添加用户
    add_user_locator = (By.CSS_SELECTOR, "#user_form > div:nth-child(1) > div > a:nth-child(3)")

    def click_add_post(self):
        """点击添加岗位"""
        self.driver.find_element(*self.add_post_locator).click()

    def input_post_name(self,post_name):
        """输入岗位名"""
        self.driver.find_element(*self.post_name_locator).send_keys(post_name)

    def choice_department(self,index=0):
        """选择所属部门"""
        select_element=self.driver.find_element(*self.select_locator)
        select=Select(select_element)
        select.select_by_index(index)

    def choice_up_post(self,index=0):
        """选择上级岗位"""
        select_element=self.driver.find_element(*self.up_locator)
        select=Select(select_element)
        select.select_by_index(index)

    def input_post_description(self,description):
        """输入岗位描述"""
        self.driver.find_element(*self.post_description_locator).send_keys(description)

    def click_save_btn(self):
        """点击保存"""
        self.driver.find_element(*self.save_btn_locator).click()

    def click_add_department(self):
        """点击添加部门"""
        self.driver.find_element(*self.add_department_locator).click()

    def input_department_name(self,department_name):
        """输入部门名"""
        self.driver.find_element(*self.department_name_locator).send_keys(department_name)

    def choice_up_department(self,index=0):
        """选择上级部门"""
        select_element = self.driver.find_element(*self.drop_locator)
        select = Select(select_element)
        select.select_by_index(index)

    def input_department_description(self,description):
        """输入部门描述"""
        self.driver.find_element(*self.department_description_locator).send_keys(description)

    def click_save(self):
        """点击部门保存按钮"""
        self.driver.find_element(*self.save_locator).click()

    def click_alter(self):
        """点击修改按钮"""
        self.driver.find_element(*self.alter_locator).click()

    def click_check(self):
        """点击查看按钮"""
        self.driver.find_element(*self.check_locator).click()

    def add_department_mistake_tips(self):
        """添加部门错误消息提示"""
        return self.driver.find_element(*self.add_department_mistake_tips_locator).text

    def add_department_success_tips(self):
        """添加部门成功信息提示"""
        return self.driver.find_element(*self.add_department_success_tips_locator).text

    def add_post_success_tips(self):
        """添加岗位成功信息提示"""
        return self.driver.find_element(*self.add_post_success_tips_locator).text

    def add_post_mistake_tips(self):
        """添加岗位失败信息提示"""
        return self.driver.find_element(*self.add_post_mistake_tips_locator).text

    def add_user_tips(self):
        """添加用户成功信息提示"""
        return self.driver.find_element(*self.add_user_tips_locator).text

    def click_add_user(self):
        """点击添加用户"""
        self.driver.find_element(*self.add_user_locator).click()